#include <iostream>
#include <string>
#include <vector>
using namespace std;

int prost(int v)
{
    bool f = true;
    for(int i = 2; i < v; i++)
    {
        if (v % i == 0)
        {
            f = false;
            break;
        }
    }
    return f;
}

int chislo(vector <string> mas)
{
	string v;
	int g, c;
	bool f = true;
	for (string & i: mas)
	{
		c++;
		if (i == "one") v += "1";
		if (i == "two") v += "2";
		if (i == "three") v += "3";
		if (i == "four") v += "4";
		if (i == "five") v += "5";
		if (i == "six") v += "6";
		if (i == "seven") v += "7";
		if (i == "eight") v += "8";
		if (i == "nine") v += "9";
		if (i == "zero") v += "0";
		if (c < 4)
        {
            if (i != "one" && i != "two" && i != "three" && i != "four" && i != "five" && i != "six" && i != "seven" && i != "eight" && i != "nine" && i != "zero")
            {
                f = false;
                break;
            }
        }
        else
        {
            f = false;
            break;
        }
	}
	g = atoi(v.c_str());
	return g;
}

int Min(int g)
{
	int c1, Min;
	for (int i = g - 1; i > 0; i--)
	{
		for(int j = 2; j < i; j++)
		{
			if(i % j == 0) c1++;
		}
		if(c1 == 0)
		{
			Min = i;
			break;
		}
		c1 = 0;
	}
	return Min;
}

int Max(int g)
{
	int c2, Max;
	while (Max != 0)
	{
		g++;
		for (int j = 2; j < g; j++)
		{
			if (g % j == 0) c2++;
		}
		if (c2 == 0)
		{
			Max = g;
			break;
		}
		c2 = 0;
	}
	return Max;
}

int main()
{
    string n, sl, v;
	int g, c1, c2;
	bool f = true;
    getline(cin, n);
    vector <string> mas(0);
    for(auto & i: n)
    {
        if (i != ' ') sl = sl + i;
        if (i == ' ')
        {
            mas.push_back(sl);
            sl = "";
        }
    }
    mas.push_back(sl);
	g = chislo(mas);
	f = prost(g);
	c1 = Min(g);
	c2 = Max(g);
	if (g > 99 && g < 1000)
    {
        if (f == true) cout << g;
        else
        {
            if (g - c1 > c2 - g) cout << c2;
            else cout << c1;
        }
    }
    else cout << "Wrong input";
}
